home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
program
/
progem.arc
/
gem1.asc
next >
Wrap
Text File
|
1987-10-10
|
16KB
|
347 lines
** Professional GEM **
by Tim Oren
Topic: WINDOWS, part I
10/7/85
ANTIC is proud to present the first of Tim Oren's bi-monthly columns
exploring the GEM programming environment. These columns are aimed
at professional ST developers, but we encourage everyone to join in
and collect the columns for future reference.
HELLO, WORLD!
For those whom I have not met in person or electronically, an
introduction is in order.
I am a former member of the GEM programming team at Digital Research,
Inc., where I designed and implemented the GEM Resource Construction
Set and other parts of the GEM Programmer's Toolkit. I have since
left DRI to become the user interface designer for Activenture, a
startup company which is developing CD-ROM technology for use with
the Atari ST and other systems.
The purpose of Professional GEM is to pass along some of the
information and tricks I have accumulated about GEM, and explore some
of the user interface techniques which a powerful graphics processor
such as the ST makes possible.
GROUND RULES
I am going to assume that you have both a working knowledge of the C
programming language and a copy of the ST Programmer's Toolkit with
documentation (available from Atari). If you lack either, don't
panic. You can read the columns to get the flavor of programming the
ST, and come back for a more serious visit later on.
For now, I will be using code samples that will run with the
Atari-supplied C compiler, also known as DR C-68K, or Alcyon C. I
will be using the portability macros supplied with the Toolkit, so
that the code will also be transferable to other GEM systems.
Both of these items are subject to change, depending on reader
feedback and the availability of better products.
If you do not have a copy of the source to the DOODLE.C GEM example
program, you should consider downloading a copy from SIG*ATARI.
Although it is poorly documented, it shows real-life examples of many
of the techniques I will discuss.
Getting started with a windowed graphics system seems to be like
getting into an ice-cold swimming pool: it's best done all at once.
Anyone who has looked at "Inside Macintosh" has probably noticed that
you have to have read most of it to understand any of it. GEM isn't
really much different. You have all the reference guides in your
hand, but nothing to show how it all works together.
I am hoping to help this situation by leading a series of short tours
through the GEM jungle. Each time we'll go out with a particular
goal in mind and follow the path that leads there. We'll look at the
pitfalls and strange bugs that lurk for the unwary, and show off a
few tricks to amaze the natives. The first trip leaves immediately;
our mission is to get a window onto the ST screen, with all of its
parts properly initialized.
WE DO WINDOWS
One of the most important services which a graphics interface system
provides for the user and programmer is window management.
Windows allow the user to perform more than one activity on the same
screen, to freely reallocate areas of the screen for each task, and
even to pile the information up like pages of paper to make more
room. The price for this increased freedom is (as usual) paid by
you, the programmer, who must master a more complex method of
interacting with the "outside world".
The windowing routines provided by ST GEM are the most comprehensive
yet available in a low-cost microcomputer. This article is a guide
to using these services in an effective manner.
IN THE BEGINNING
In GEM, creating a window and displaying it are two different
functions. The creation function is called wind_create, and its
calling sequence is:
handle = wind_create(parts, xfull, yfull, wfull, hfull);
This function asks GEM to reserve space in its memory for a new
window description, and to return a code or "handle" which you can
use to refer to the window in the future. Valid window handles are
positive integers; they are not memory pointers.
GEM can run out of window handles. If it does so, the value returned
is negative. Your code should always check for this situation and
ask the program's user to close some windows and retry if possible.
Handle zero is special. It refers to the "desktop", which is
predefined as light green (or gray) on the ST. Window zero is always
present and may be used, but never deleted, by the programmer.
The xfull, yfull, wfull, and hfull parameters are integers which
determine the maximum size of the window. Xfull and yfull define the
upper left corner of the window, and wfull and hfull specify its
width and height. (Note that all of the window coordinates which we
use are in pixel units.)
GEM saves these values so that the program can get them later when
processing FULL requests. Usually the best maximum size for a
window is the entire desktop area, excepting the menu bar. You can
find this by asking wind_get for the working area of the desktop
(handle zero, remember):
wind_get(0, WF_WXYWH, &xfull, &yfull, &wfull, &hfull);
Note that WF_WXYWH, and all of the other mnemonics used in this
article, are defined in the GEMDEFS.H file in the ST Toolkit.
The parts parameter of wind_create defines what features will be
included in the window when it is drawn. It is a word of single bit
flags which indicate the presence/absence of each feature. To
request multiple features, the flags are "or-ed" together. The flags'
mnemonics and meanings are:
NAME- A one character high title bar at the top of the window.
INFO- A second character line below the NAME.
MOVER- This lets the user move the window around by "dragging" in
the NAME area. NAME also needs to be defined.
CLOSER - A square box at the upper left. Clicking this control
point asks that the window be removed from the screen.
FULLER - A diamond at upper right. Clicking this control point
requests that the window grow to its maximum size, or shrink back
down if it is already big.
SIZER - An arrow at bottom right. Dragging the SIZER lets the
user choose a new size for the window.
VSLIDE - defines a right-hand scroll box and bar for the window.
By dragging the scroll bar, the user requests that the window's
"viewport" into the information be moved. Clicking on the gray box
above the bar requests that the window be moved up one "page".
Clicking below the bar requests a down page movement. You have to
define what constitutes a page or line in the context of your
application.
UPARROW - An arrow above the right scroll bar. Clicking here
requests that the window be moved up one "line". Sliders and arrows
almost always appear together.
DNARROW - An arrow below the right scroll bar. Requests that window
be moved down a line.
HSLIDE - These features are the horizontal equivalent of the
RTARROW above. They appear at the bottom of the window. Arrows
LFARROW usually indicate "character" sized movement left and right.
"Page" sized movement has to be defined by each application.
It is important to understand the correspondence between window
features and event messages which are sent to the application by the
GEM window manager. If a feature is not included in a window's
creation, the user cannot perform the corresponding action, and your
application will never receive the matching message type. For
example, a window without a MOVER may not be dragged by the user,
and your app will never get a WM_MOVED message for that window.
Another important principle is that the application itself is
responsible for implementing the user's window action request when a
message is received. This gives the application a chance to accept,
modify, or reject the user's request.
As an example, if a WM_MOVED message is received, it indicates that
the user has dragged the window. You might want to byte or word
align the requested position before proceeding to